package oop.chat.search;

import java.util.ArrayList;
import oop.chat.user.Contact;
import oop.chat.user.ContactList;
import oop.chat.user.UserAccount;

/**
 * search the user contacts for a special year
 * @author Eric
 */
class YearSearch extends Search 
{
	/**
     * initialize a new year search
     * @param	type	SearchType
     */
    public YearSearch(SearchType type) 
	{
        super(type);
    }

    /**
	 * main search function
	 * @param		searchWord		String
	 * @param		user			UserAccount
	 * @return		searchResults	ArrayList<Contact>
	 */
    @Override
    public Object doSearch(String searchWord, UserAccount user) 
	{
		searchWord = searchWord.toLowerCase();
		ArrayList<Contact> searchResults = new ArrayList<>();
		ContactList[] contactLists = user.getContactLists();
		for(ContactList list : contactLists)
		{
			for(Contact contact : list.getUserContacts().values())
			{
				if(contact.getYear().toLowerCase().contains(searchWord))
				{
					searchResults.add(contact);
				}
			}
		}
		//return result set
		return searchResults;		
    }
}